<template>  
  <div class="formSelect">
      <el-select
        v-model="value1"
        :multiple='!comData.node.isRadio'
        :placeholder="placeholder"
        @visible-change='handleChange($event)'>
        <el-option
          v-for="item in comData.node.options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    </div>
</template>

<script>
export default {
  props:{
    label:{
        type:String,
        default:''
    },
    placeholder:{
        type:String,
        default:''
    },
    comData: {
        type:Object,
        default:''
    }
  },
  data() {
    return {
      value1: ''
    }
  },
  mounted() {
    if(this.comData.node.isRadio) {
      this.value1 = '1'
    }
    let obj = {}
    this.comData.node.options.map(item => {
      if(item.value == this.value1) {
        obj[this.label] = item.label;
      }
    })
    this.$emit('setFormData', obj)
  },
  methods: {
    handleChange(state) {
      let array = []
      let obj = {}
      this.comData.node.options.map(item => {
        if(this.value1.indexOf(item.value) != -1) {
          array.push(item.label)
        }
      })
      obj[this.label] = array;
      this.$emit('setFormData', obj)
    }
  }
}
</script>

<style lang="less" scoped>

</style>